SWIG_URL = "http://downloads.sourceforge.net/project/swig/swig/swig-%(VERSION)s/swig-%(VERSION)s.tar.gz"
SWIGWIN_URL = "http://downloads.sourceforge.net/project/swig/swigwin/swigwin-%(VERSION)s/swigwin-%(VERSION)s.zip"
DEFAULT_VERSION = "2.0.4"
VERSIONS = ["2.0.0", "2.0.1", "2.0.2", "2.0.3", "2.0.4"]

#note: windows uses DownloadAndCopyBuilder so no depends are needed
DEPENDS = ["pcre"] 

DESCRIPTION = """ Simplified Wrapper and Interface Generator
              Windows: Download and Copy
              Linux: Configure Make Install """

from source.builders import ConfigureMakeBuilder, DownloadAndCopyBuilder
import os

def urldecider( machine, dirs, version):
  return { "Linux" : SWIG_URL % {"VERSION" : version},
           "Windows" : SWIGWIN_URL % {"VERSION" : version} }[machine.platform]

def decider( machine, dirs ):
  return { "Linux" : MakeSwigBuilder,
           "Windows" : DownloadAndCopyBuilder }[machine.platform]

class MakeSwigBuilder( ConfigureMakeBuilder ):
  """ subclass of CMakeBuilder with custom build and install step """

  def configureparameters( self ):
    """cmake configure with CMAKE_CONFIGURE options"""
    return ["--with-pcre-prefix="+self.dependencies['pcre'].targetpath()]

  def configure (self):
    pcre_include = self.dependencies["pcre"].getincludedir()
    os.environ["C_INCLUDE_PATH"] = os.pathsep.join([pcre_include])
    pcre_lib = self.dependencies["pcre"].getlibdir()
    os.environ["LIBRARY_PATH"] = os.pathsep.join([pcre_lib])
    os.environ["PCRE_LIBS"] = pcre_lib+os.sep+"libpcre.so"
    ConfigureMakeBuilder.configure(self)

URL = urldecider
BUILDER = decider
